import Rx from 'rxjs/Rx'

export default {
  state: {
    playing: {
      show: false
    },
    actionSheet: {
      menus: {},
      show: false,
      subject: null
    }
  },
  mutations: {
    showPlayingList(state) {
      state.playing.show = true
    },
    closePlayingList(state) {
      state.playing.show = false
    },
    showActionSheet(state, menus) {
      state.actionSheet.menus = menus
      state.actionSheet.show = true
    },
    closeActionSheet(state) {
      state.actionSheet.show = false
    }
  },
  actions: {
    notifyActionSheet({commit, state}, options) {
      state.actionSheet.subject = new Rx.AsyncSubject()
      state.actionSheet.subject.subscribe({ 
        next: (v) => options.handler[v](),
        complete: () => commit('closeActionSheet')
      })
      commit('showActionSheet', options.menus)
    },
    resFromActionSheet({state}, menu) {
      state.actionSheet.subject.next(menu)
      state.actionSheet.subject.complete()
    }
  }
}